New optional .gitlab-ci-local-ignores file to list file to ignore to sync with jobs - #1884
New optional .gitlab-ci-local-ignores file to list file to ignore to sync with jobs#1884jrd wants to merge 1 commit into
.gitlab-ci-local-ignores file to list file to ignore to sync with jobs#1884Conversation
|
@jrd Can we add a test to verify and avoid future regressions? |
|
I’ll add a test later this day (I’m UTC+2) |
Done. Hope the test is good enough… (because I didn’t cover all cases) |
| `--exclude-from=<(git ls-files -o --directory | awk '{print "/"$0}')`, // eslint-disable-line @stylistic/quotes | ||
| `--exclude-from=<(cat ${Utils.safeBashString(ignoresFile)} 2>/dev/null || true)`, |
There was a problem hiding this comment.
| `--exclude-from=<(git ls-files -o --directory | awk '{print "/"$0}')`, // eslint-disable-line @stylistic/quotes | |
| `--exclude-from=<(cat ${Utils.safeBashString(ignoresFile)} 2>/dev/null || true)`, | |
| "--exclude-from=<(git ls-files -o --directory | awk '{print \"/\"$0}')", | |
| ...await fs.pathExists(ignoresFile) ? [`--exclude-from=${Utils.safeBashString(ignoresFile)}`] : [], |
| }) | ||
| .option("ignores-file", { | ||
| type: "string", | ||
| description: "Path to a ignores file", |
There was a problem hiding this comment.
| description: "Path to a ignores file", | |
| description: "Path to an ignores file", |
| } | ||
| parser = await Parser.create(argv, writeStreams, pipelineIid, jobs); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, ".docker"); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); |
There was a problem hiding this comment.
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); | |
| await Utils.rsyncTrackedFiles(cwd, stateDir, path.resolve(cwd, argv.ignoresFile), ".docker"); |
| const pipelineIid = await state.getPipelineIid(cwd, stateDir); | ||
| parser = await Parser.create(argv, writeStreams, pipelineIid, jobs); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, ".docker"); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); |
There was a problem hiding this comment.
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); | |
| await Utils.rsyncTrackedFiles(cwd, stateDir, path.resolve(cwd, argv.ignoresFile), ".docker"); |
| const pipelineIid = await state.incrementPipelineIid(cwd, stateDir); | ||
| parser = await Parser.create(argv, writeStreams, pipelineIid, jobs); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, ".docker"); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); |
There was a problem hiding this comment.
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); | |
| await Utils.rsyncTrackedFiles(cwd, stateDir, path.resolve(cwd, argv.ignoresFile), ".docker"); |
| // Copy git tracked files to build folder if shell isolation enabled. | ||
| if (!imageName && this.argv.shellIsolation) { | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${safeJobName}`); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${this.argv.ignoresFile}`, `${safeJobName}`); |
There was a problem hiding this comment.
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${this.argv.ignoresFile}`, `${safeJobName}`); | |
| await Utils.rsyncTrackedFiles(cwd, stateDir, path.resolve(cwd, this.argv.ignoresFile), `${safeJobName}`); |
| --- | ||
| test-job: | ||
| script: | ||
| - tree -a |
| } | ||
| parser = await Parser.create(argv, writeStreams, pipelineIid, jobs); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, ".docker"); | ||
| await Utils.rsyncTrackedFiles(cwd, stateDir, `${cwd}/${argv.ignoresFile}`, ".docker"); |
There was a problem hiding this comment.
${cwd}/${argv.ignoresFile} breaks --ignores-file /abs/path → ${cwd}//abs/path. Verified: original reports test-job > 2 (exclusions silently dropped), 1 after path.resolve. The 2>/dev/null || true is what hides it; a typo'd path fails silently too.
| --- | ||
| test-job: | ||
| script: | ||
| - tree -a |
There was a problem hiding this comment.
Not asserted, and not installed here, so the whole test file fails locally with tree: command not found. Passes only because GitHub runners ship it.
There was a problem hiding this comment.
oh I see, can I replace it with find ?
…o sync with jobs. The file could also be specified on command line. Format should follow the `rsync` ignore format. Also never sync the `.git/lfs` directory which, if it exists, is usually huge.
|
Should be good now. |
The file could also be specified on command line.
Format should follow the
rsyncignore format.Also never sync the
.git/lfsdirectory which, if it exists, is usually huge.This pull request could replace #1883 if this solution is preferred.
Summary by cubic
Add an optional
.gitlab-ci-local-ignoresfile and a--ignores-fileflag to exclude files fromrsyncacross pipelines, stages, and shell isolation. Always exclude.git/lfs, and safely escape the ignore file path.New Features
.gitlab-ci-local-ignoresusingrsyncignore syntax (default path).--ignores-fileto set a custom ignore file path.Bug Fixes
rsyncto prevent command injection.Written for commit dc2b57b. Summary will update on new commits.